package cc.ufinity.networkdiagnose.widget;

import cc.ufinity.networkdiagnose.adapter.GridAdapter;
import cc.ufinity.networkdiagnose.view.R;
import android.app.Activity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.GridView;
import android.widget.ListAdapter;

public class TestWidget extends GeneralTestWidget {
    public Activity ctx;
    // 客户感知
    private int[] icons1 = new int[] { R.drawable.web_auth, R.drawable.ping, R.drawable.sim_auth, 
    		                           R.drawable.peap_auth, R.drawable.http_test, R.drawable.ftp_test };
    // 业务质量
    private int[] icons2 = new int[] { R.drawable.ap_relevance, R.drawable.segregate_test, R.drawable.roam };
    // 无线网络
    private int[] icons3 = new int[] { R.drawable.signal_ratio, R.drawable.signal_leve, };
    private GridView meunGV;
    private GridView meunGV2;
    private GridView meunGV3;

    public TestWidget(Activity context) {
        super(context);
        inflate(context, R.layout.networktest, this);
        this.ctx = context;
        meunGV = (cc.ufinity.networkdiagnose.view.MyGridView) this.findViewById(R.id.meunGridView1);
        meunGV2 = (cc.ufinity.networkdiagnose.view.MyGridView) this.findViewById(R.id.meunGridView2);
        meunGV3 = (cc.ufinity.networkdiagnose.view.MyGridView) this.findViewById(R.id.meunGridView3);
        String[] meunText1 = getResources().getStringArray(R.array.meunGridView1);
        String[] meunText2 = getResources().getStringArray(R.array.meunGridView2);
        String[] meunText3 = getResources().getStringArray(R.array.meunGridView3);
        ListAdapter adapter1 = new GridAdapter(ctx, icons1, meunText1);
        ListAdapter adapter2 = new GridAdapter(ctx, icons2, meunText2);
        ListAdapter adapter3 = new GridAdapter(ctx, icons3, meunText3);
        meunGV.setAdapter(adapter1);
        meunGV2.setAdapter(adapter2);
        meunGV3.setAdapter(adapter3);
        meunGV2.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View v, int index, long id) {
                switch (index) {
                case 0:
                    doApRelevTest();
                    break;
                case 1:
                    doSegregateTest();
                    break;
                case 2:
                    doRoamTest();
                    break;
                }
            }
        });
        meunGV3.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View v, int index, long id) {
                switch (index) {
                case 0:
                    doWifiSNRTest();
                    break;
                case 1:
                    showRssi();
                    break;
                }

            }
        });
        meunGV.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> arg0, View v, int index, long id) {
                switch (index) {
                case 0:
                    doWebAuth();

                    break;
                case 1:
                    doPing();

                    break;
                case 2:
                    break;
                case 3:
                    doPeap();
                    break;
                case 4:
                    doHttpTest();
                    break;
                case 5:
                    doFtpTest();
                    break;
                }
            }
        });
    }
    private void doPeap() {
        PeapWidget peap = new PeapWidget(ctx);
        ctx.setContentView(peap);
        peap.scanWifi();
    }
    private void doRoamTest() {
        ctx.overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
        RoamTestWidget rw = new RoamTestWidget(ctx);
        ctx.setContentView(rw);
    }

    private void doWifiSNRTest() {
        WifiSnrTestWidget ww = new WifiSnrTestWidget(ctx);
        ctx.setContentView(ww);
    }

    private void doSegregateTest() {
        SegregateTestWidget sw = new SegregateTestWidget(ctx);
        ctx.setContentView(sw);
    }

    private void doApRelevTest() {
        ApRelevanceTestWidget aw = new ApRelevanceTestWidget(ctx);
        ctx.setContentView(aw);
        aw.scanWifi();

    }

    private void doHttpTest() {
        HttpTestWidget httpTest = new HttpTestWidget(ctx);
        ctx.setContentView(httpTest);
        httpTest.startHttpTest();
    }

    private void doFtpTest() {
        FtpTestWidget ftpTest = new FtpTestWidget(ctx);
        ctx.setContentView(ftpTest);
        ftpTest.statFtpTest();
    }

    private void doPing() {
        PingWidget ping = new PingWidget(ctx);
        ctx.setContentView(ping);
    }

    private void showRssi() {
        RssiWidget rw = new RssiWidget(ctx);
        ctx.setContentView(rw);
    }

    private void doWebAuth() {
        WebauthTestWidget w = new WebauthTestWidget(ctx);
        ctx.setContentView(w);
        // w.start();
    }
}
